import {Toast} from 'vant'

export const terminal = {
  //  获取设备类型
  terminals() {
    var u = navigator.userAgent
    let a = {
      android: u.indexOf("Android") > -1 || u.indexOf("Linux") > -1,
      // 是否为iPhone或者QQHD浏览器
      iPhone: u.indexOf("iPhone") > -1,
      // 是否iPad
      iPad: u.indexOf("iPad") > -1,
    }
    return a;
  },
  //  获取日期
  getDaysInMonth(month, year) {
    let daysInMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
    if (month === '2' || month === 2) {
      daysInMonth[1] = (((0 === year % 4) && (0 !== (year % 100))) || (0 === year % 400)) === true ? 29 : 28;
    }
    let flag = month.substr(0, 1);
    if (flag === 0) {
      month = month.substr(1, 1);
    }
    return daysInMonth[month - 1];
  },
  //  打开加载框
  Start() {
    try {
      plus.nativeUI.showWaiting("正在加载...");
    } catch (e) {
    }
  },
  //  关闭加载框
  end() {
    try {
      plus.nativeUI.closeWaiting();
    } catch (e) {
    }
  },
  _error(error) {
    try {
      plus.nativeUI.closeWaiting();
    } catch (e) {
      console.log("plus问题");
    }
    let err = error.message;
    if (err === "Network Error") {
      Toast("网络异常!");
    }else if (err.includes("timeout")) {
      Toast("网络超时,请重试!");
    } else {
      Toast(err);
    }
  }
}
export default terminal
